<?php

$mcrp = './../';
include_once($mcrp . 'functions/session.php');
include_once($mcrp . 'functions/log.php');
include_once($mcrp . 'functions/nanoparser.php');

if(isset($_GET['last']))
{
	if(isset($_SESSION['lastcode'])) echo $_SESSION['lastcode'];
	else echo '0';
}
else
{
	if(!isset($_POST['code'])) die('No input');
	$code = str_replace(array('\r\n', '\n'), chr(13).chr(10), $_POST['code']);
	$result = NanoMakeProgram($code, -1);
	foreach($result['errors'] as $e)
		echo $e . "\n";
	if($result['success'] == true)
	{
		echo ':::' . $result['hex'];
		$_SESSION['lastprgm'] = $result['hex'];
		$_SESSION['lastcode'] = $code;
	}
	else
		unset($_SESSION['lastprgm']);

	LogCompilation($code);
}

?>